package com.gxa.controller.asset;

import com.gxa.common.utils.R;
import com.gxa.entity.asset.CheckApply;
import com.gxa.entity.asset.CheckRecords;
import com.gxa.entity.asset.search.CheckApplyAndRecordSearchMap;
import com.gxa.service.asset.CheckRecordsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



import static com.gxa.common.utils.R.error;
import static com.gxa.common.utils.R.ok;

/**
 * @Description:
 * @Author: zhuiyi
 * @CreatTime: 2022/10/13 16:24
 **/
@Api(tags = "设备检定--->检定登记")
@RestController
@RequestMapping("/check-records")
public class CheckRecordsController {

    @Autowired
    private CheckRecordsService service;


    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("检定登记列表接口")
    @GetMapping("/list")
    public R queryAll(CheckApplyAndRecordSearchMap map){

        return ok("successs").put("data",service.queryByPage(map));
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("新增检定登记接口")
    @PostMapping("/add")
    public R add(@RequestBody CheckRecords device){
       if (service.save(device)){
        return ok("add success");
       }
        return error("添加失败！");
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("删除检定登记接口")
    @DeleteMapping("/del/{id}")
    public R del(@PathVariable("id") Integer id){
        boolean b = service.removeById(id);
        if(b){
            return ok("删除成功！");
        }
        return error("del error");
    }
    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("根据id查询检定登记接口")
    @GetMapping("/queryById/{id}")
    public R queryById(@PathVariable("id") Integer id){
        CheckRecords checkRecords = service.getById(id);
            if (checkRecords != null){
                return ok("queryById").put("data",checkRecords);
            }

        return error("query error");
    }
    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("编辑检定登记接口")
    @PutMapping("/edit")
    public R edit(@RequestBody CheckRecords device){
        boolean b = service.updateById(device);
        if(b){
            return ok("更新成功！");
        }
        return error("edit error");
    }
}
